package com.zengdada.authority.utils.transformdata;

import java.io.BufferedReader;
import java.io.Reader;
import java.sql.Clob;

/**
 * @Auther: 12614
 * @Contact: 1261438511@qq.com
 * @Date: 2019/3/7 13:57
 * @Description: Clob 转 String
 */
public class TransformDataClobToString extends TransformData<Clob, String> {
    @Override
    public String transform(Clob obj) {
        StringBuilder sb = new StringBuilder();
        try {
            try (Reader is = obj.getCharacterStream()) {// 得到流
                try (BufferedReader br = new BufferedReader(is)) {
                    String s = br.readLine();
                    while (s != null) {// 执行循环将字符串全部取出付值给StringBuffer由StringBuffer转成STRING
                        sb.append(s);
                        s = br.readLine();
                    }
                }
            }
        } catch (Exception e) {
            return "";
        }
        return sb.toString();
    }

    @Override
    public boolean equalType(Object o) {
        return o instanceof Clob;
    }
}
